package com.sms.biz.impl;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.sms.biz.ISingleSmsBiz;
import com.sms.dao.ISingleSmsDAO;
import com.sms.po.TWaitsend;
import com.sms.po.Whitelist;


/**
 * @author 20120101 by cxh
 */
public class SingleSmsBizImpl implements ISingleSmsBiz {
	private ISingleSmsDAO issd = null;

	public void setIssd(ISingleSmsDAO issd) {
		this.issd = issd;
	}

	@Override
	public List<TWaitsend> showAllSendmsg() {
		return issd.showAllSendmsg();
	}

	@Override
	public List<TWaitsend> showAllSendmsgByPage(String userId,String phone,int start, int limit) {
		// 离线查询
		DetachedCriteria criteria = DetachedCriteria
				.forClass(TWaitsend.class);
		// 如果条件标题不为空,那么将条件标题附加上
		if (!"".equals(phone) && null != phone) {
			criteria.add(Restrictions.like("phone", phone,
					MatchMode.ANYWHERE));
		}
		criteria.add(Restrictions.eq("userId", userId));
		criteria.add(Restrictions.eq("taskId", new Long(0)));
		criteria.addOrder(Order.desc("id"));
		if (start <= 0) {start = 0;		}
		if (limit <= 0) {limit = 10;	}
		return issd.showAllSendmsgByPage(criteria, start, limit);
	}
	@Override
	public int getAllSendmsgCount() {
		// 离线查询
		DetachedCriteria criteria = DetachedCriteria
				.forClass(TWaitsend.class);
		// 如果条件标题不为空,那么将条件标题附加上
//		if (!"".equals(userId) && null != userId) {
//			criteria.add(Restrictions.like("userId", userId,
//					MatchMode.ANYWHERE));
//		}
		return issd.getAllSendmsgCount(criteria);
	}
	
	public boolean addSendmsg(TWaitsend ts) {
		try {
			issd.addSendmsg(ts);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
	}
}
